/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.usfirst.frc2084.robotsimulator.gui;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 * The drop zone where robot code will be dragged. Only the top level folder
 * containing all the robot code should be placed here.
 *
 * @author Sam
 */
public class FileDropZone extends JPanel {
    
    private BufferedImage image;    // background image

    public FileDropZone() {
        super();
        initDropZone();
        setSize(500, 500);
    }

    private void initDropZone() {
        try {
            image = ImageIO.read(new File("resources\\LandingZone.png"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        FileDropper dropper = new FileDropper(this, new FileDropper.Listener() {
            @Override
            public void filesDropped(File[] files) {
                try { // copy files to new directory
                    final File root = new File("code");
                    CodeCleaner.copyDirectory(files[0], root);  // copy all the files to the new folder
                    CodeCleaner.cleanDirectory(root);           // clean up the imports
                } catch (IOException ex) {
                    Logger.getLogger(FileDropZone.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(image, 0, 0, this);
    }
}
